package com.aaa.web.service.impl.secondcarserviceimpl;

import com.aaa.entity.Employee;
import com.aaa.entity.secondcar.NewSecondCar;
import com.aaa.entity.secondcar.SecondCarEntrepotMessage;
import com.aaa.util.EmpUtil;
import com.aaa.web.commons.Result;
import com.aaa.web.commons.SecondCarEntrepotQuery;
import com.aaa.web.dao.secondcardao.SecondCarEntrepotDao;
import com.aaa.web.service.secondcarservice.SecondCarEntrepotService;
import com.aaa.web.systemconst.ISystemConst;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;



/**
 * @ClassName
 * @Description 门店二手车仓库
 * @Author 许一鑫
 * @Date
 **/
@Service
public class SecondCarEntrepotServiceImpl implements SecondCarEntrepotService {
    /**自动注入dao*/
    @Autowired
    private SecondCarEntrepotDao dao;

    /**查询出所有在仓库中未卖出的二手车信息*/
    @Override
    public Map getSecondCarEntrepotMessage(SecondCarEntrepotQuery query) {
        int page=query.getPage();
        int size=query.getLimit();
        PageHelper.startPage(page,size);
        //获取登录员工
        Employee emp= EmpUtil.getEmp();
        query.setEmpschoolid(emp.getSchoolid());
        //存放返回信息的map
        Map map=new HashMap();
        List<SecondCarEntrepotMessage> list=dao.getSecondCarEntrepotMessage(query);
        map.put("data",list);
        map.put("count",dao.getSecondCarEntrepotcount(query));
        map.put("code",ISystemConst.SU_COD);
        map.put("msg","");

        return map;
    }
    /**查询出二手车仓库中的车辆详细描述*/
    @Override
    public String getSecondCarDescribe(SecondCarEntrepotMessage s) {

        return dao.getSecondCarDescribe(s);
    }
    /**将二手车仓库中的车辆信息修改为卖出*/
    @Override
    public Result sellSecondCar(SecondCarEntrepotMessage s) {
        //设置返回值
        Result result=new Result();
        dao.sellSecondCar(s);
        result.setCode(ISystemConst.SUCCESS_CODE);
        return result;
    }
    /**动态获取学校门店下拉框的数据*/
    @Override
    public List<Map> getschool() {
        return dao.getschool();
    }
    /**动态获取电车型号下拉框的数据*/
    @Override
    public List<Map> getgoodsname() {
        return dao.getgoodsname();
    }
    /**添加新的二手车仓库信息*/
    @Override
    public Result setNewSecondCar(NewSecondCar n) {
        //设置返回值
        Result result=new Result();
        //查询该二手车出厂码，车型是否存在
        String carcode= (String) dao.findcarcode(n);
        if(carcode!=null || carcode!=""){
            //添加二手车
            dao.setNewSecondCar(n);
            result.setCode(ISystemConst.SUCCESS_CODE);
            return result;
        }
        result.setCode(ISystemConst.DEFEAT_CODE);
        return result;
    }
}
